﻿
namespace DevOnServer
{
    public class CRandgaManager : CTimed
    {
        public CRandgaManager(CGameServer server)
        {
            m_server = server;
        }

        public override void update()
        {
            if (m_randga1 == null && s_time >= m_nextRandga1)
            {
                if(m_server.Worlds.ContainsKey((int)DefineWorld.WI_WORLD_MADRIGAL))
                {
                    CVec3Df pos = new CVec3Df();

                    switch (CRandom.random(0, 3))
                    {
                        case 0:
                            pos = new CVec3Df(4609.0f, 60.0f, 4409.0f);
                            break;

                        case 1:
                            pos = new CVec3Df(4390.0f, 20.0f, 3998.0f);
                            break;

                        case 2:
                            pos = new CVec3Df(4496.0f, 60.0f, 3846.0f);
                            break;
                    }

                    m_randga1 = m_server.Worlds[(int)DefineWorld.WI_WORLD_MADRIGAL].createMonsterObject(
                        m_server.DataManager.MoverProperties[(int)DefineObj.MI_RANGDA01], pos);
                }
                else
                    m_nextRandga1 = s_time + 3600000;
            }
            else if (m_randga1 != null && !m_randga1.IsAlive)
            {
                m_randga1 = null;
                m_nextRandga1 = s_time + 3600000;
            }

            if (m_randga2 == null && s_time >= m_nextRandga2)
            {
                if (m_server.Worlds.ContainsKey((int)DefineWorld.WI_WORLD_MADRIGAL))
                {
                    CVec3Df pos = new CVec3Df();

                    switch (CRandom.random(0, 3))
                    {
                        case 0:
                            pos = new CVec3Df(2587.0f, 52.0f, 3603.0f);
                            break;

                        case 1:
                            pos = new CVec3Df(3589.0f, 36.0f, 3849.0f);
                            break;

                        case 2:
                            pos = new CVec3Df(4080.0f, 30.0f, 3711.0f);
                            break;
                    }

                    m_randga2 = m_server.Worlds[(int)DefineWorld.WI_WORLD_MADRIGAL].createMonsterObject(
                        m_server.DataManager.MoverProperties[(int)DefineObj.MI_RANGDA02], pos);
                }
                else
                    m_nextRandga2 = s_time + 3600000;
            }
            else if (m_randga2 != null && !m_randga2.IsAlive)
            {
                m_randga2 = null;
                m_nextRandga2 = s_time + 3600000;
            }

            if (m_randga3 == null && s_time >= m_nextRandga3)
            {
                if (m_server.Worlds.ContainsKey((int)DefineWorld.WI_WORLD_MADRIGAL))
                {
                    CVec3Df pos = new CVec3Df();

                    switch (CRandom.random(0, 3))
                    {
                        case 0:
                            pos = new CVec3Df(3187.0f, 36.0f, 3192.0f);
                            break;

                        case 1:
                            pos = new CVec3Df(3512.0f, 117.0f, 2190.0f);
                            break;

                        case 2:
                            pos = new CVec3Df(2805.0f, 109.0f, 2336.0f);
                            break;
                    }

                    m_randga3 = m_server.Worlds[(int)DefineWorld.WI_WORLD_MADRIGAL].createMonsterObject(
                        m_server.DataManager.MoverProperties[(int)DefineObj.MI_RANGDA03], pos);
                }
                else
                    m_nextRandga3 = s_time + 3600000;
            }
            else if (m_randga3 != null && !m_randga3.IsAlive)
            {
                m_randga3 = null;
                m_nextRandga3 = s_time + 3600000;
            }

            if (m_randga4 == null && s_time >= m_nextRandga4)
            {
                if (m_server.Worlds.ContainsKey((int)DefineWorld.WI_DUNGEON_VOLCANE))
                {
                    CVec3Df pos = new CVec3Df();

                    switch (CRandom.random(0, 3))
                    {
                        case 0:
                            pos = new CVec3Df(601.0f, 89.0f, 1509.0f);
                            break;

                        case 1:
                            pos = new CVec3Df(509.0f, 87.0f, 597.0f);
                            break;

                        case 2:
                            pos = new CVec3Df(1498.0f, 88.0f, 1524.0f);
                            break;
                    }

                    m_randga4 = m_server.Worlds[(int)DefineWorld.WI_DUNGEON_VOLCANE].createMonsterObject(
                        m_server.DataManager.MoverProperties[(int)DefineObj.MI_RANGDA04], pos);
                }
                else
                    m_nextRandga4 = s_time + 3600000;
            }
            else if (m_randga4 != null && !m_randga4.IsAlive)
            {
                m_randga4 = null;
                m_nextRandga4 = s_time + 3600000;
            }
        }

        private CGameServer m_server;

        private CMonster m_randga1;

        private int m_nextRandga1;

        private CMonster m_randga2;

        private int m_nextRandga2;

        private CMonster m_randga3;

        private int m_nextRandga3;

        private CMonster m_randga4;

        private int m_nextRandga4;
    }
}